/* eslint-disable */
// eslint-disable-next-line
import { MrxDbgUiPrPoint, MxFun, MxDbText } from "mxdraw";

class MxDbTextAnnotation extends MxDbText {
  getGripPoints() {
    const { x, y, z } = this.position;
    const leftPoint = new THREE.Vector3(x - 5, y, z);  // 左偏移5
    const rightPoint = new THREE.Vector3(x + 5, y, z); // 右偏移5
    return [this.position, leftPoint, rightPoint];
  }
  moveGripPointsAt(index, offset) { // 移除类型注解
    const [position, leftPoint, rightPoint] = this.getGripPoints();
    if (index === 0) this.position = position.add(offset);  // 移动文本位置
    if (index === 1) this.position = leftPoint.add(offset); // 移动左边夹点
    if (index === 2) this.position = rightPoint.add(offset); // 移动右边夹点
    return true;
  }
}

// 文字批注绘制函数
const drawTextAtPoint = async () => {
  const getPoint = new MrxDbgUiPrPoint();
  const textAnnotation = new MxDbTextAnnotation();
  // 设置图层为“Comment”
  textAnnotation.layer = "Comment";
  // 获取点击的位置作为文字的起始位置
  const startPoint = await getPoint.go();
  if (startPoint) {
    textAnnotation.position = startPoint;
  } else {
    throw new Error("获取位置失败");
  }

  // 提示输入文本
  const textInput = prompt("请输入文字批注内容");
  if (textInput) {
    textAnnotation.text = textInput;
    MxFun.getCurrentDraw().addMxEntity(textAnnotation);  // 将文字批注添加到绘图中
  } else {
    alert("没有输入文本！");
  }
};

export { drawTextAtPoint };
